package org.fatmansoft.teach.repository;

import org.fatmansoft.teach.models.Course;
import org.fatmansoft.teach.models.Student;
import org.fatmansoft.teach.models.StudentCourse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.relational.core.sql.In;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface StudentCourseRepository extends JpaRepository<StudentCourse, Integer> {

    @Query(value = "select max(studentCourseId) from StudentCourse ")
    Integer getMaxId();

    void deleteByStudentAndCourse(Student student, Course course);
    List<StudentCourse> findByStudentStudentId(Integer id);
    List<StudentCourse> findByCourseNum(String num);

    @Query(value = "from StudentCourse where course.name like %?1%")
    List<StudentCourse> findByCourseName(String courseName);

    @Query(value = "from StudentCourse where student.person.num like %?1%")
    Optional<StudentCourse> findByPersonNum(String num);

    Optional<StudentCourse> findByStudentPersonNumAndCourseNum(String studentNum, String courseNum);
}
